package com.solarStruggle.util

import java.io.{ByteArrayOutputStream, InputStream}
import java.net.{URL}

object ResourceLoader {

	def getResource(relativeName: String): InputStream = 
		Thread.currentThread.getContextClassLoader.getResourceAsStream(relativeName)

	def getResourceURL(relativeName: String): URL =
		Thread.currentThread.getContextClassLoader.getResource(relativeName)
 
	def getResourceBytes(relativeName: String): Array[Byte] = {
		val input = getResource(relativeName)
		val output = new ByteArrayOutputStream
		val buffer = Array.make[Byte](1024, 0)
		var charsRead = -1
		do {
			charsRead = input.read(buffer, 0, 1024)
			if(charsRead != -1) {
				output.write(buffer, 0, charsRead)
			}
		} while(charsRead != -1)
		return output.toByteArray
	} 
}
